package com.practice.designMode.Decorator;

import java.util.*;

/**
 * 使用装饰器模式，增强我们的Set
 * @param <E>
 */
public class MySet<E> implements Set<E> {

    private Set<E> set;
    public MySet(Set<E> set) {
        this.set = set;
    }

    // 增强的功能 记录被删除的元素
    private List<E> list = new ArrayList<>();

    @Override
    public int size() {
        return set.size();
    }

    @Override
    public boolean isEmpty() {
        return set.isEmpty();
    }

    @Override
    public boolean contains(Object o) {
        return set.contains(o);
    }

    @Override
    public Iterator<E> iterator() {
        return null;
    }

    @Override
    public Object[] toArray() {
        return new Object[0];
    }

    @Override
    public <T> T[] toArray(T[] a) {
        return null;
    }

    @Override
    public boolean add(E e) {
        return set.add(e);
    }

    @Override
    public boolean remove(Object o) {
        if(set.remove(o)){
            list.add((E) o);
            return true;
        }
        return false;
    }

    @Override
    public boolean containsAll(Collection<?> c) {
        return false;
    }

    @Override
    public boolean addAll(Collection<? extends E> c) {
        return false;
    }

    @Override
    public boolean retainAll(Collection<?> c) {
        return false;
    }

    @Override
    public boolean removeAll(Collection<?> c) {
        return false;
    }

    @Override
    public void clear() {

    }

    @Override
    public String toString() {
        return set.toString() + " 被删除的元素为：" + list.toString();
    }
}
